package org.qb.mapreduce.rewritePartioner;

import com.sun.org.apache.bcel.internal.generic.SWITCH;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Partitioner;

//partioner方法是在map和reducer中间，shuffel机制中
public class ProvincePartioner extends Partitioner<Text,FlowBean> {


    /**
     * 重写partioner方法，
     * 将控制不同手机号，输出不同的文件中
     * @param text 手机号
     * @param flowBean
     * @param i
     * @return
     */
    @Override
    public int getPartition(Text text, FlowBean flowBean, int i) {

        String prePhone = text.toString().substring(0,3);

        int partion;

       switch (prePhone){
           case "136":
               partion = 0;
               break;
           case "137":
               partion = 1;
               break;
           case "138":
               partion = 2;
               break;
           case "139":
               partion = 3;
               break;
           default: partion = 4;
       }

        return partion;
    }
}
